node {
   def javaHome = '/base/java8'
   def mvnHome = '/home/mvn3'
   def workspace = pwd()
   def project_name = 'summer_boss_backend.jar'
   def project_home = 'pipeline_docker_boss_backend'
   def rs_ip = '172.17.0.9'
   def rs_port = '22'
   def rs_user = 'root'
   def url = 'https://gitee.com/john-summer/summer_boss_backend.git'
   def imageRepo = '172.17.0.9:9001/service'
   //代码获取
   stage('Preparation') { // for display purposes
	    git branch: "${branch}", url: "${url}"
   }
   //构建
   stage('Build') {
      // Run the maven build
      if (isUnix()) {
         sh "${mvnHome}/bin/mvn -Dmaven.test.skip=true clean package"
      } else {
         bat(/"${mvnHome}\bin\mvn" -Dmaven.test.skip=true clean package/)
      }
   }

   //构建 docker 镜像并推送到私有仓库
   stage('Docker Build') {
     sh "docker build -t ${imageRepo}/summer_boss_backend.jar:stable -f dockerfile ."
     sh "docker push ${imageRepo}/summer_boss_backend.jar:stable"
   }

   //分发运行脚本
   stage('Uplad Script') {
     sh "ssh -p ${rs_port} ${rs_user}@${rs_ip} 'mkdir -p /app/${project_home}'"
     sh "scp -r -P ${rs_port} ${workspace}/deploy-pipeline-docker.sh ${rs_user}@${rs_ip}:/app/${project_home}/"
   }

  //运行镜像
  stage('Run') {
     //sh "ssh -p ${rs_port} ${rs_user}@${rs_ip} 'docker rm -f boss_backend'"
     //sh "ssh -p ${rs_port} ${rs_user}@${rs_ip} 'docker run -d -p 8889:8082 -e 'SPRING_PROFILES_ACTIVE=prd' -v /app/logs/:/app/logs --name boss_backend 172.17.0.9:9001/service/summer_boss_backend.jar:stable'"
     sh "ssh -p ${rs_port} ${rs_user}@${rs_ip} 'sh /app/${project_home}/deploy-pipeline-docker.sh'"
  }
}